package com.qxzn.app.medicalhealth;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.PagerSnapHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.qxzn.app.bean.MedicalHealthBean;
import com.qxzn.app.medicalhealth.activity.AddedMedicalDeviceActivity;
import com.qxzn.app.medicalhealth.activity.ChooseUserActivity;
import com.qxzn.app.medicalhealth.activity.TakeMedicalRemindActivity;
import com.qxzn.app.page.BaseFragment;
import com.qxzn.app.medicalhealth.activity.FamilyMedicalRecordsActivity;
import com.qxzn.app.medicalhealth.adapter.MedicalHealthAdapter;
import com.qxzn.app.util.AppUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MedicalHealthFragment extends BaseFragment implements View.OnClickListener {

    @BindView(R2.id.tv_medical_and_health)
    TextView tvMedicalAndHealth;
    @BindView(R2.id.rv_health)
    RecyclerView rvHealth;
    @BindView(R2.id.tv_health_push)
    TextView tvHealthPush;
    @BindView(R2.id.iv_health_push)
    ImageView ivHealthPush;
    @BindView(R2.id.tv_attribute)
    TextView tvAttribute;

    private List<MedicalHealthBean> dataList = new ArrayList<>();
    private MedicalHealthAdapter adapter;

    @Override
    protected int initLayout() {
        return R.layout.fragment_medical_health;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void initData(Bundle savedInstanceState) {
        addData();
        rvHealth.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false));
        adapter = new MedicalHealthAdapter(getActivity(), dataList, this);
        rvHealth.setAdapter(adapter);
        PagerSnapHelper snapHelper = new PagerSnapHelper();
        snapHelper.attachToRecyclerView(rvHealth);
    }

    private void addData() {
        MedicalHealthBean bean = new MedicalHealthBean();
        bean.setName("家庭病例");
        bean.setCls(FamilyMedicalRecordsActivity.class);

        MedicalHealthBean bean1 = new MedicalHealthBean();
        bean1.setCls(TakeMedicalRemindActivity.class);
//        HashMap<String, String> params = new HashMap<>();
//        params.put("title", "baidu");
//        params.put("url", "http://www.baidu.com");
//        bean1.setParams(params);
        bean1.setName(ChooseUserActivity.remindTitle);

        MedicalHealthBean bean2 = new MedicalHealthBean();
        bean2.setName("医疗设备");
        bean2.setCls(AddedMedicalDeviceActivity.class);
        dataList.add(bean);
        dataList.add(bean1);
        dataList.add(bean2);
    }

    @Override
    public void onClick(View v) {
        AppUtil.showLog("点击");
        MedicalHealthBean bean = (MedicalHealthBean) v.getTag();
        AppUtil.startActivity(getActivity(), bean.getCls(), bean.getParams());
        AppUtil.showLog("点击" + bean.getName());
    }

}
